import * as echarts from 'echarts'
import colors from './colors'

// 柱状图
export function configBarSeries({ count = 1, showLabel = false } = {}) {
  const config = new Array(count).fill(null).map(() => ({
    type: 'bar',
    barMinWidth: 10,
    barMaxWidth: '10%',
    barMinHeight: 0,
    label: {
      show: showLabel,
      position: 'top'
    }
  }))
  return config
}
// 堆叠柱状图
export function configBarStackSeries({ count = 1, stack = '' } = {}) {
  const config = new Array(count).fill(null).map(() => ({
    type: 'bar',
    barMinWidth: 10,
    barMaxWidth: '10%',
    barMinHeight: 0,
    stack: stack
  }))
  return config
}
// 饼图
export function configPie() {}
// 折线
export function configLineSeries({ count = 1, showLabel = false } = {}) {
  const config = new Array(count).fill(null).map(() => ({
    type: 'line',
    label: {
      show: showLabel,
      position: 'top'
    },
    cursor: 'default'
  }))
  return config
}

// 渐变柱状图
export function configBarGradientSeries({
  count = 1,
  color = [
    {
      color: colors.gradient.color1,
      color_gradient: colors.gradient.color1_gradient
    },
    {
      color: colors.gradient.color2,
      color_gradient: colors.gradient.color2_gradient
    },
    {
      color: colors.gradient.color3,
      color_gradient: colors.gradient.color3_gradient
    },
    {
      color: colors.gradient.color4,
      color_gradient: colors.gradient.color4_gradient
    },
    {
      color: colors.gradient.color5,
      color_gradient: colors.gradient.color5_gradient
    },
    {
      color: colors.gradient.color6,
      color_gradient: colors.gradient.color6_gradient
    }
  ],
  showLabel = false
} = {}) {
  const config = new Array(count).fill(null).map((item, index) => ({
    type: 'bar',
    barMinWidth: 10,
    barMaxWidth: '10%',
    barMinHeight: 0,
    showBackground: true,
    backgroundStyle: {
      color: 'rgba(115, 159, 250, 0.1)'
    },
    itemStyle: {
      color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
        { offset: 0, color: color[index % color.length].color },
        { offset: 1, color: color[index % color.length].color_gradient }
      ])
    },
    label: {
      show: showLabel,
      color: color[index % color.length].color,
      position: 'top'
    }
  }))
  return config
}
